<template>

  <div small-bg class="current-volume-container">
    <dv-decoration-9 style="width:350px;height:230px;">
      <div color-green font-600 class="content" bg="~ dark/0">
        <div class="current-volume-container">
          <div v-if="loading" class="loading-animation">
            <div class="spinner"></div>
            <span style="font-size: 16px; font-weight: bold; text-shadow: 0 0 5px rgba(0, 191, 255, 0.5);">加载中...</span>
          </div>
          <div v-else class="current-volume">
            <h3 style="font-size: 14px;">当前到件量</h3>
            <p class="animated-number">{{ currentVolume }}</p>
          </div>
        </div>
      </div>
    </dv-decoration-9>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import axios from 'axios';

const currentVolume = ref(0);
const loading = ref(true);

const fetchCurrentVolume = async () => {
  try {
    const response = await axios.get("http://localhost:8082/logistics/currentVolume");
    if (response.data.code === 200 && response.data.data) {
      currentVolume.value = response.data.data.currentVolume;
    } else {
      console.error("Failed to fetch current volume:", response.data?.msg || "No data returned");
    }
  } catch (error) {
    console.error("Error fetching current volume:", error.message || "Unknown error");
  } finally {
    loading.value = false;
  }
};

onMounted(() => {
  fetchCurrentVolume();
});
</script>

<style scoped>
.current-volume-container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  background-color: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  padding: 20px;
}



.current-volume {
  text-align: center;
}

.current-volume h3 {
  color: #00bfff;
  margin-bottom: 10px;
  font-size: 18px;
}

.current-volume p {
  font-size: 28px;
  font-weight: bold;
  color: #1e90ff;
}

.loading-animation {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(0, 191, 255, 0.3);
  border-radius: 50%;
  border-top-color: #00bfff;
  border-right-color: #00bfff;
  border-bottom-color: #00bfff;
  animation: spin 1.5s linear infinite;
  margin-bottom: 15px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.animated-number {
  font-size: 28px;
  font-weight: bold;
  color: #1e90ff;
  text-shadow: 0 0 10px rgba(30, 144, 255, 0.7);
  transition: all 0.5s ease;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
  }
}
</style>
